
public class Main {


    //二叉树前序遍历带高度
    public static void preWithLevel(TreeNode root,int level){

        if(root==null){
            return ;
        }
        //记得开始时传入level即可
        System.out.println(root.val+" "+level);
        preWithLevel(root.left,level+1);
        preWithLevel(root.right,level+1);
    }

    public static void main(String[] args) {
        TreeNode root= BuildTree.buildTree();
        preWithLevel(root,1);


    }
}
